package com.cxm.qyyz.di.module;

import android.content.Context;

import com.cxm.qyyz.app.App;
import com.cxm.qyyz.core.DataManager;
import com.cxm.qyyz.core.db.DatabaseHelper;
import com.cxm.qyyz.core.db.DatabaseHelperImpl;
import com.cxm.qyyz.core.http.DataApi;
import com.cxm.qyyz.core.http.HttpHelper;
import com.cxm.qyyz.core.http.HttpHelperImpl;
import com.cxm.qyyz.core.http.RetrofitManager;
import com.cxm.qyyz.di.scope.AppScope;
import com.cxm.qyyz.di.scope.ContextLife;

import dagger.Module;
import dagger.Provides;

@Module
public class AppModule {

    private final App application;

    public AppModule(App application) {
        this.application = application;
    }

    @ContextLife("Application")
    @AppScope
    @Provides
    public Context provideApplicationContext() {
        return application.getApplicationContext();
    }

    @AppScope
    @Provides
    public DataApi provideApi() {
        RetrofitManager instance = RetrofitManager.getInstance();
//        if (BuildConfig.DEBUG){
//            instance.setRetrofit();
//        }
        return instance.create(DataApi.class);
    }

    @AppScope
    @Provides
    public HttpHelper provideHttpHelper(HttpHelperImpl helper) {
        return helper;
    }

    @AppScope
    @Provides
    public DatabaseHelper provideDatabaseHelper(DatabaseHelperImpl helper) {
        return helper;
    }

    @AppScope
    @Provides
    public DataManager provideDataManager(HttpHelper httpHelper, DatabaseHelper databaseHelper) {
        return new DataManager(httpHelper, databaseHelper);
    }
}
